package com.yuandian.business.monitor.controller;


import com.yuandian.api.business_monitor.po.IndexParams;
import com.yuandian.base.service.ITaskDataService;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.security.annotation.Inner;
import com.yuandian.business.monitor.service.IIndexService;
import com.yuandian.vo.TrendDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 说明：首页controller
 *
 * @Author lishilei
 * @Date 2023/03/13 10:53
 */
@RestController
@RequestMapping("/home/index")
@Api(value = "index", tags = "BPM首页接口")
public class IndexController {

	@Autowired
	private IIndexService indexService;

//    @Autowired
//    private ITableConfigService tableConfigService;

	@Autowired
	private ITaskDataService taskDataService;

	/**
	 * 根据表名查询表周期信息
	 *
	 * @param tableName 表名
	 * @return 通用返回对象
	 */
	@ApiOperation("根据表名查询表周期信息")
	@GetMapping("/queryTableSaveCycleInfoByName/{tableName}")
	public R queryTableSaveCycleInfoByName(@NotNull @PathVariable String tableName) {
//        return R.ok(tableConfigService.queryTableSaveCycleInfoByName(tableName));
		return R.ok();
	}

	/**
	 * 查询系统访问量趋势
	 * 业务访问量-busi_sys_visit_trend_m-DetailMinuteStatTask-详单表分钟统计-SystemVisitTrendStatHandler-延迟3分钟-api/modules/home/index/querySystemVisitTrend
	 *
	 * @param params 首页搜索条件
	 * @return 通用返回对象
	 */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 			value = "系统id", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "currentDate",   			value = "当前时间", 				paramType = "query", 	required = true, 	dataType = "Long"),
	})
	@ApiOperation("查询系统访问量趋势")
	@PostMapping("/querySystemVisitTrend")
	public R querySystemVisitTrend(@RequestBody IndexParams params) {
		TrendDataVo trendDataVo = taskDataService.getTrendObject("详单表分钟统计", params.getStartTime(), params.getEndTime(), indexService.querySystemVisitTrend(params));
		return R.ok(trendDataVo);
	}

    /**
     * 查询系统平均响应时长趋势
     * 业务办理时长-busi_sys_visit_trend_m-DetailMinuteStatTask-详单表分钟统计-SystemVisitTrendStatHandler-延迟3分钟-api/modules/home/index/querySystemAvgDealTimeTrend
     * @param params 首页搜索条件
     * @return 通用返回对象
     */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 			value = "系统id", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "currentDate",   			value = "当前时间", 				paramType = "query", 	required = true, 	dataType = "Long"),
	})
	@ApiOperation("查询系统平均响应时长趋势")
    @PostMapping("/querySystemAvgDealTimeTrend")
    public R querySystemAvgDealTimeTrend(@RequestBody IndexParams params) {
        TrendDataVo trendDataVo=taskDataService.getTrendObject("详单表分钟统计",params.getStartTime(),params.getEndTime(),indexService.querySystemAvgDealTimeTrend(params));
        return R.ok(trendDataVo);
    }

    /**
     * 查询系统健康度趋势
     * 业务健康度-busi_sys_visit_trend_m-DetailMinuteStatTask-详单表分钟统计-SystemVisitTrendStatHandler-延迟3分钟-api/modules/home/index/querySystemHealthRatioTrend
     * @param params 首页搜索条件
     * @return 通用返回对象
     */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 			value = "系统id", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "currentDate",   			value = "当前时间", 				paramType = "query", 	required = true, 	dataType = "Long"),
	})
	@ApiOperation("查询系统健康度趋势")
    @PostMapping("/querySystemHealthRatioTrend")
    public R querySystemHealthRatioTrend(@RequestBody IndexParams params) {
        TrendDataVo trendDataVo=taskDataService.getTrendObject("详单表分钟统计",params.getStartTime(),params.getEndTime(),indexService.querySystemHealthRatioTrend(params));
        return R.ok(trendDataVo);
    }

    /**
     * 查询系统告警访问量趋势
     * 业务告警访问量-busi_sys_visit_trend_m-DetailMinuteStatTask-详单表分钟统计-SystemVisitTrendStatHandler-延迟3分钟-api/modules/home/index/querySystemAlarmTrend
     * @param params 首页搜索条件
     * @return 通用返回对象
     */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId", 			value = "系统id", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "Long"),
			@ApiImplicitParam(name = "currentDate",   			value = "当前时间", 				paramType = "query", 	required = true, 	dataType = "Long"),
	})
	@ApiOperation("查询系统告警访问量趋势")
    @PostMapping("/querySystemAlarmTrend")
    public R querySystemAlarmTrend(@RequestBody IndexParams params) {
        TrendDataVo trendDataVo=taskDataService.getTrendObject("详单表分钟统计",params.getStartTime(),params.getEndTime(),indexService.querySystemAlarmTrend(params));
        return R.ok(trendDataVo);
    }
}
